package com.example.windowdemo.window.strategy;

import android.content.Context;
import android.view.View;

import com.example.windowdemo.callback.WindowStrategy;
import com.example.windowdemo.window.Window;

/**
 * @author: njb
 * @date: 2023/8/3 14:03
 * @desc:
 */
public class WindowStrategyBuilder<T> {
    private final Context context;
    private final WindowStrategy windowStrategy;
    private boolean isFullScreen;
    private boolean hasTitleBar;
    private int width;
    private int height;
    private T data;
    private View contentView;
    private int x;
    private int y;
    private int gravity;

    public WindowStrategyBuilder(Context context, WindowStrategy windowStrategy) {
        this.context = context;
        this.windowStrategy = windowStrategy;
    }

    public WindowStrategyBuilder<T> setFullScreen(boolean isFullScreen) {
        this.isFullScreen = isFullScreen;
        return this;
    }

    public WindowStrategyBuilder<T> setTitleBar(boolean hasTitleBar) {
        this.hasTitleBar = hasTitleBar;
        return this;
    }

    public WindowStrategyBuilder<T> setSize(int width, int height) {
        this.width = width;
        this.height = height;
        return this;
    }

    public WindowStrategyBuilder<T> setPosition(int x, int y) {
        this.x = x;
        this.y = y;
        return this;
    }

    public WindowStrategyBuilder<T> setGravity(int gravity) {
        this.gravity = gravity;
        return this;
    }

    public WindowStrategyBuilder<T> setData(T data) {
        this.data = data;
        return this;
    }

    public WindowStrategyBuilder<T> setContentView(View contentView) {
        this.contentView = contentView;
        return this;
    }

    public StrategyWindow<T> build() {
        StrategyWindow<T> window = new StrategyWindow<>(context, windowStrategy);
        window.initView();
        window.setFullScreen(isFullScreen);
        window.setTitleBar(hasTitleBar);
        window.setSize(width, height);
        window.setPosition(x, y);
        window.setGravity(gravity);
        window.setData(data);
        window.addView(contentView);
        return window;
    }
}
